package ace.module.weixin.test.core.config;

import ace.cmp.core.utils.SystemClockUtils;
import ace.cmp.id.generator.api.LongIdGenerator;
import ace.module.weixin.core.impl.dao.entity.WxsMiniAppConfig;
import ace.module.weixin.core.impl.dao.repository.WxsMiniAppConfigRepository;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaUserService;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.redisson.api.RedissonClient;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author caspar
 * @date 2023/2/14 11:46
 */
@Configuration
@AllArgsConstructor
public class BootstrapAutoConfig {

  private final LongIdGenerator idGenerator;
  private final WxsMiniAppConfigRepository miniAppConfigRepository;

  @Bean
  public WxsMiniAppConfig defaultWxsMiniAppConfig() {
    WxsMiniAppConfig wxsMiniAppConfig =
        WxsMiniAppConfig.builder()
            .id(idGenerator.get())
            .appId("testAppId")
            .appSecret("testAppSecret")
            .token(StringUtils.EMPTY)
            .aesKey(StringUtils.EMPTY)
            .msgDataFormat(StringUtils.EMPTY)
            .updateTime(SystemClockUtils.currentTimeMillis())
            .createTime(SystemClockUtils.currentTimeMillis())
            .rowVersion(1L)
            .build();
    this.miniAppConfigRepository.insert(wxsMiniAppConfig, false);
    return wxsMiniAppConfig;
  }

  @MockBean
  public WxMaService wxMaService;

  @MockBean
  public WxMaUserService wxMaUserService;
  @MockBean
  public RedissonClient redissonClient;
}
